const OSS = require('ali-oss');
const moment = require('moment');

let expirationTime3 = null; // STS token 过期时间
let userclient=null; //网校用户公共属性文件

// 初始化 oss client
export function initOssUserClient(accessKeyId, accessKeySecret, stsToken, expiration, bucket = "newxuejinguser") {
	userclient = new OSS({
		secure: true,
		accessKeyId,
		accessKeySecret,
		stsToken,
		region: 'oss-cn-beijing',
		bucket
	});
expirationTime3 = expiration;
return userclient;
}

// 检查 oss 实例以及过期时间
export function checkOssUserClient() {
const current = moment();
return moment(expirationTime3).diff(current) < 0 ? null : userclient;
}

// 用于 sts token 失效、用户登出时注销 oss client
export function destroyOssUserClient() {
	userclient=null;
}
